// 判断用户是否登录
(()=>{
   //1.获取地址栏中数据 ?email=ding@qq.com&uid=1
   //var data=location.search
   //alert(location.href);
   //截取字符串中邮箱地址
   //var a=data.split('=');
  //alert(a[1]);
  let obj=new URLSearchParams(location.search);
  // console.log(obj);
  let uname = obj.get("uname");
  // alert(uname);
  //1.创建对象
  let xhr = new XMLHttpRequest();
  //2.保存session数据添加属性#在客户端加密保存session数据
  xhr.withCredentials = true;
  //3.指定接收数据函数
  xhr.onreadystatechange = ()=> {
    //6.接收数据
    if(xhr.readyState==4 && xhr.status==200) {
    //  console.log(xhr.responseText);
      let obj=JSON.parse(xhr.responseText);
      // console.log(obj);
      if(obj.code<=0){
        let user_img = document.getElementById("user_img");
        let user_name = document.getElementById("user_name");
        user_img.style.display = "none";
        user_name.innerHTML = "";
      }else {
        let user_img = document.getElementById("user_img");
        let user_name = document.getElementById("user_name");
        user_img.style.display = "block";
        user_img.src = obj.data.user_photo;
        user_name.innerHTML = obj.data.uname;
        let jump_mymusic = document.getElementById("jump_mymusic");
        let playlist = document.getElementById("playlist");
        jump_mymusic.href = `http://127.0.0.1:8848/html/mymusic.html?uname=${user_name.innerHTML}`;
        playlist.href = `http://127.0.0.1:8848/html/playlist.html?uname=${user_name.innerHTML}`;
        // alert(user_name.innerHTML);
      }
    }
  }
  //4.指定服务器地址
  let url =`http://127.0.0.1:8848/user/v1/search?uname=${uname}`;
  xhr.open("GET",url,true);
  //5.发送请求
  xhr.send();
})();